package com.crm.jdy.controller.drp;

import com.crm.jdy.common.dto.HWorkInfoDto;
import com.crm.jdy.common.dto.WOutInfoDto;
import com.crm.jdy.common.pojo.HWorkInfo;
import com.crm.jdy.common.pojo.WOutInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.drp.HWorkInfoService;
import com.crm.jdy.service.drp.WOutInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 考核表信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月12日
*
*/
@Api(tags = "hWorkInfo", description = "考核表信息")
@RestController
@RequestMapping("/hWorkInfo")
public class HWorkInfoController{

    @Reference(version = "${service.version}", check = false)
    HWorkInfoService wOutInfoService;

    @RateLimit()
    @ApiOperation("项目信息")
    @PostMapping("/seleteHWorkInfo")
    public ResultVo seleteHWorkInfo(@RequestBody HWorkInfoDto wOutInfo){
        PageInfo<HWorkInfo> list = wOutInfoService.seleteHWorkInfo(wOutInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新项目信息")
    @PostMapping("/updateHWorkInfo")
    public ResultVo updateHWorkInfo(@ApiParam(value = "wOutInfo", required = true)
                                   @Validated @RequestBody HWorkInfo wOutInfo){
        boolean index = wOutInfoService.updateHWorkInfo(wOutInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加项目信息")
    @PostMapping("/addHWorkInfo")
    public ResultVo addHWorkInfo(@ApiParam(name = "wOutInfo", required = false)
                                @Validated @RequestBody HWorkInfo wOutInfo){
        boolean list  = wOutInfoService.addHWorkInfo(wOutInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除项目信息")
    @DeleteMapping("deleteHWorkInfo/{workId}")
    public ResultVo deleteHWorkInfo(@NotNull @ApiParam(name = "workId", value = "workId", required = true) @PathVariable String workId){
        boolean b = wOutInfoService.removeHWorkInfo(workId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}